﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using System.Data;
using Ultility;

namespace Entity
{
    public partial class Entity_Employee : Component
    {
        DBAccess _access = new DBAccess();
        public Entity_Employee()
        {
            InitializeComponent(); 
        }

        public Entity_Employee(IContainer container)
        {
            container.Add(this);

            InitializeComponent();
        }
        public bool _Insert_employee(string employeeID, string name, int sex, string birthDay, string personID, string dateOfIssue, string placeOfIssue, string hometown, string email, string mobile, string addressE, string salary, byte[] images, string homePhone)
        {
            SqlParameter[] para = {
                                      new SqlParameter("@EmployeeID",SqlDbType.NVarChar),
                                      new SqlParameter("@Name",SqlDbType.NVarChar),
                                      new SqlParameter("@Sex",SqlDbType.Bit),
                                      new SqlParameter("@BirthDay",SqlDbType.SmallDateTime),
                                      new SqlParameter("@PersonID",SqlDbType.Char),
                                      new SqlParameter("@DateOfIssue",SqlDbType.DateTime),
                                      new SqlParameter("@PlaceOfIssue",SqlDbType.NVarChar),
                                      new SqlParameter("@Hometown",SqlDbType.NVarChar),
                                      new SqlParameter("@Email",SqlDbType.NVarChar),
                                      new SqlParameter("@Mobile",SqlDbType.Char),
                                      new SqlParameter("@AddressE",SqlDbType.NVarChar),
                                      new SqlParameter("@Salary",SqlDbType.Char),
                                      new SqlParameter("@Images",SqlDbType.Image),
                                      new SqlParameter("@HomePhone",SqlDbType.Char)
                                  };
            para[0].Value = employeeID;
            para[1].Value =name;
            para[2].Value=sex;
            para[3].Value=birthDay;
            para[4].Value = personID;
            para[5].Value = dateOfIssue;
            para[6].Value = placeOfIssue;
            para[7].Value = hometown;
            para[8].Value = email;
            para[9].Value = mobile;
            para[10].Value = addressE;
            para[11].Value = salary;
            para[12].Value = images;
            para[13].Value =homePhone;
            return _access._ExcuteNonQuery("sp_Insert_Employee", para);
        }
        
        //Chọn tất cả các Nhân Viên
        public DataSet _SelectAll_Employee()
        { 
            return _access._ExcuteQuery("sp_Select_Employee",null);   
        }

        public DataSet _FindbyName(string name)
        {
            SqlParameter[] para = { new SqlParameter("@name",SqlDbType.NVarChar) };
            para[0].Value = name;
            return _access._ExcuteQuery("sp_FindbyName_Employee", para);
        }
        public DataSet _SelectOne_Employee(string id)
        {
            SqlParameter[] para = { new SqlParameter("@id", SqlDbType.NVarChar) };
            para[0].Value = id;
            return _access._ExcuteQuery("sp_SelectOne_Employee", para);
        }
        public bool _Delete_employee(string id)
        {
            SqlParameter[] para = { new SqlParameter("@id", SqlDbType.NVarChar) };
            para[0].Value = id;
            return _access._ExcuteNonQuery("sp_Delete_eployee", para);
        }

        public bool _Update_Employee(string employeeID, string name, int sex, string birthDay, string personID, string dateOfIssue, string placeOfIssue, string hometown, string email, string mobile, string addressE, string salary, byte[] images, string homePhone)
        {
            SqlParameter[] para = {
                                      new SqlParameter("@EmployeeID",SqlDbType.NVarChar),
                                      new SqlParameter("@Name",SqlDbType.NVarChar),
                                      new SqlParameter("@Sex",SqlDbType.Bit),
                                      new SqlParameter("@BirthDay",SqlDbType.SmallDateTime),
                                      new SqlParameter("@PersonID",SqlDbType.Char),
                                      new SqlParameter("@DateOfIssue",SqlDbType.DateTime),
                                      new SqlParameter("@PlaceOfIssue",SqlDbType.NVarChar),
                                      new SqlParameter("@Hometown",SqlDbType.NVarChar),
                                      new SqlParameter("@Email",SqlDbType.NVarChar),
                                      new SqlParameter("@Mobile",SqlDbType.Char),
                                      new SqlParameter("@AddressE",SqlDbType.NVarChar),
                                      new SqlParameter("@Salary",SqlDbType.Char),
                                      new SqlParameter("@Images",SqlDbType.Image),
                                      new SqlParameter("@HomePhone",SqlDbType.Char)
                                  };
            para[0].Value = employeeID;
            para[1].Value = name;
            para[2].Value = sex;
            para[3].Value = birthDay;
            para[4].Value = personID;
            para[5].Value = dateOfIssue;
            para[6].Value = placeOfIssue;
            para[7].Value = hometown;
            para[8].Value = email;
            para[9].Value = mobile;
            para[10].Value = addressE;
            para[11].Value = salary;
            para[12].Value = images;
            para[13].Value = homePhone;
            return _access._ExcuteNonQuery("sp_Update_employee", para);
        }

        public DataSet _ListUser()
        {
            return _access._ExcuteQuery("sp_SelectAll_Acc", null);
        }

        public DataSet _Select_AccType() {
            return _access._ExcuteQuery("sp_Select_AccType", null);
        }

        public DataSet _Select_AcountOfType(string idType)
        {
            SqlParameter[] para = { new SqlParameter("@idTypet", SqlDbType.Char), };
            para[0].Value = idType;
            return _access._ExcuteQuery("sp_select_acountofType", para);
        }

        public DataSet _Select_EmployAcc()
        {
            return _access._ExcuteQuery("sp_select_EmployCoTK", null);
        }

        public DataSet _Select_EmployNOTAcc()
        {
            return _access._ExcuteQuery("sp_select_EmployKocoTK", null);
        }


        public bool _Insert_newAcc(string maNV, string id, string pass, string accType)
        {
            SqlParameter[] para = {
                                      new SqlParameter("@id",SqlDbType.NVarChar),
                                      new SqlParameter("@pass",SqlDbType.NVarChar),
                                      new SqlParameter("@employID",SqlDbType.NVarChar),
                                      new SqlParameter("@accTypeID",SqlDbType.NVarChar)
                                  };
            para[0].Value = id;
            para[1].Value = pass;
            para[2].Value = maNV;
            para[3].Value = accType;
            return _access._ExcuteNonQuery("sp_Insert_newAcc", para);
        }
    }
}
